﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Sayeet
{
    public partial class DebugWindow : Form
    {
        AppData appData;

        public DebugWindow(AppData ad)
        {
            InitializeComponent();
            appData = ad;
        }

        public delegate void PrintDelegate(string t);

        private void PrintHandler(string t)
        {
            //debugTextBox.Text += t;
            debugTextBox.AppendText(t);
            debugTextBox.ScrollToCaret();
        }

        public void addText(string text)
        {
            addText(text, "");
        }

        public void addText(string text, string prefix)
        {
            string t = text + "\n";

            if (prefix != "")
            {
                t = t.Insert(0, prefix);
                t = t.Replace("\n", "\n" + prefix);
                t = t.TrimEnd(prefix.ToCharArray());
            }
            
            if (InvokeRequired)
            {
                Invoke(new PrintDelegate(PrintHandler), t);
            }
            else
            {
                PrintHandler(t);
            }

            
        }
    }
}
